package com.ruyuan.user.server.controller.handler;

import com.ruyuan.common.model.BusinessException;
import com.ruyuan.common.web.model.WebResponse;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author xx
 */
@Component
@Aspect
public class UserControllerExceptionHandler {

    @Around(value = "execution(* com.ruyuan.user.server.controller.*.*(..))")
    public Object controllerAround(ProceedingJoinPoint jp) {
        try {
            Object[] args = jp.getArgs();
            return jp.proceed(args);
        } catch (BusinessException e) {
            return WebResponse.failWithMsg(e.getErrorCode().getMsg());
        } catch (Throwable e) {
            return WebResponse.failWithMsg("系统出错了,请联系开发者");
        }
    }

}
